package basicType;

/**
 * @author Created by chenxin34 on 2019/1/27 上午10:29.
 */
public class IntegerTest {
    public static void main(String[] args) {
        Integer x = Integer.MIN_VALUE;
        x = -1;
        System.out.println(Integer.toBinaryString(x));
        long xx = x;
        System.out.println(Long.toBinaryString(xx));
        Long y = 0xffffffffffffffffL;
        System.out.println(y);

        x = x >> 31;
        System.out.println("after shift right");
        System.out.println(Integer.toBinaryString(x));
        System.out.println(x);

        int z = 5;
        System.out.println(Integer.toBinaryString(z));
        z = z >> 31;
        System.out.println("after shift right");
        System.out.println(Integer.toBinaryString(z));
        System.out.println(z);

        int ll = Integer.toBinaryString(int_to_zigzag(-10000000)).length();
        int originLengthLow = Integer.toBinaryString(-10000000).length();
        System.out.println(ll);
        System.out.println(originLengthLow);

//        findZigzagNoEffectDigit();
    }

    private static int findZigzagNoEffectDigit() {
        int low = Integer.MIN_VALUE, high = -1;
        int ll = Integer.toBinaryString(int_to_zigzag(low)).length();
        int originLengthLow = Integer.toBinaryString(low).length();
        int mid = 0;
        int ans = 0;
        while (low < high) {
            mid = (int) (((long)low + (long) high) / 2);
            originLengthLow = Integer.toBinaryString(mid).length();
            ll = Integer.toBinaryString(int_to_zigzag(mid)).length();
            System.out.println("mid = " + mid);
            System.out.println("ll = " + ll + " ol = " + originLengthLow);
            if (ll <= originLengthLow - 8) {
                high = mid - 1;
                if (ll <= originLengthLow - 8) {
                    ans = mid;
                }
            } else {
                low = mid + 1;
            }
            System.out.println("low = " + low + " high = " + high);
        }
        System.out.println("ans= " + ans);
        return 0;
    }

    public static int int_to_zigzag(int n) {
        return (n <<1) ^ (n >>31);
    }

    public static int zigzag_to_int(int n) {
        return(n >>> 1) ^ -(n & 1);
    }
}
